package com.yunsc.admin.controller.store;

import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.store.dto.UserGradeDTO;
import com.yunsc.store.service.YunscUserGradeService;
import com.yunsc.store.vo.UserGradeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version: 1.0
 * @Author: adan
 * @description: 用户等级controller
 * @date: 2024-04-19 22:11
 */
@Api(value = "用户等级接口", tags = "UserGradeController")
@Slf4j
@RestController()
@RequestMapping("/user/grade")
public class UserGradeController {

    @Resource
    private YunscUserGradeService userGradeService;

    @GetMapping("/all")
    public Result<?> queryUserGradeAll(){
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        List<UserGradeVO> userGradeAll = userGradeService.queryUserGradeAll(currentStoreId);
        return Result.resultList(userGradeAll);
    }

    @ApiOperation("查询等级列表")
    @GetMapping("/list")
    public Result<?> queryUserGradeList(@RequestParam("page") Integer page){
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        PageResult<UserGradeVO> userGradeList = userGradeService.queryUserGradeList(page,currentStoreId);
        return Result.resultPageList(userGradeList);
    }

    @ApiOperation("修改等级")
    @PostMapping("/edit")
    public Result<?> editUserGrade(@RequestBody @Validated(ValidationGroups.Update.class) UserGradeDTO userGradeParam){
        userGradeService.editUserGrade(userGradeParam);
        return Result.ok();
    }

    @ApiOperation("删除等级")
    @PostMapping("/delete")
    public Result<?> removeUserGrade(@RequestBody @Validated(ValidationGroups.Delete.class) UserGradeDTO userGradeParam){
        userGradeService.removeUserGrade(userGradeParam.getGradeId());
        return Result.ok();
    }

    @ApiOperation("添加等级")
    @PostMapping("/add")
    public Result<?> addUserGrade(@RequestBody UserGradeDTO userGradeParam){
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        userGradeService.addUserGrade(userGradeParam, currentStoreId);
        return Result.ok();
    }

}
